<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 微信用户
 */
class CreateWxUser extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //微信用户表
        Schema::create('wx_users', function (Blueprint $table) {
            $table->increments('user_id')->comment('用户ID');
            $table->string('appid', 64)->default('')->comment('微信应用ID');
            $table->string('openid', 40)->default('')->comment('用户openId');
            $table->string('unionid', 40)->default('')->comment('用户untionId');
            $table->string('nickname', 100)->default('')->comment('用户昵称');
            $table->tinyInteger('sex')->default(0)->comment('性别');
            $table->string('headimgurl', 200)->default('')->comment('用户头像路径');
            $table->string('language', 20)->default('')->comment('用户的语言');
            $table->string('country', 30)->default('')->comment('国家');
            $table->string('province', 30)->default('')->comment('省份');
            $table->string('city', 50)->default('')->comment('城市');
            $table->timestamp('first_subscribe_time')->nullable()->comment('首次关注时间');
            $table->timestamp('subscribe_time')->nullable()->comment('关注时间戳');
            $table->timestamp('unsubscribe_time')->nullable()->comment('取消关注时间戳');
            $table->tinyInteger('subscribe')->default(0)->comment('用户是否订阅该公众号标识');
            $table->string('remark', 50)->default('')->comment('用户备注');
            $table->unsignedInteger('groupid')->default(0)->comment('用户分组ID');
            $table->string('tagid_list', 50)->default('')->comment('用户标签ID列表');
            $table->unsignedTinyInteger('is_lock')->default(0)->comment('是否拉黑');
            $table->string('subscribe_scene', 30)->default('')->comment('用户关注的渠道来源');
            $table->unsignedInteger('qr_scene')->default(0)->comment('二维码扫码场景值');
            $table->string('qr_scene_str', 50)->default('')->comment('二维码扫码场景描述');
            $table->string('phone', 50)->default('')->comment('用户绑定的手机号（国外手机号会有区号）');
            $table->string('pure_phone', 50)->default('')->comment('没有区号的手机号');
            $table->string('country_code', 10)->default('')->comment('区号');
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['appid','openid'], 'uk_openid');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::dropIfExists('wx_users');
    }
}
